package com.briup.util;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.briup.bean.Category;
import com.briup.bean.Ext.CategoryExt;
import com.briup.mapper.CategoryMapper;

import java.util.ArrayList;
import java.util.List;


public class CategoryListener implements ReadListener<CategoryExt> {
    private CategoryMapper mapper;
    private List<CategoryExt> categoryList = new ArrayList<>();

    public CategoryListener(CategoryMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void invoke(CategoryExt categoryExt, AnalysisContext analysisContext) {
        if ("被删除".equals(categoryExt.getDeleted())) {
            categoryExt.setDeleted("1");
        } else if ("未被删除".equals(categoryExt.getDeleted())) {
            categoryExt.setDeleted("0");
        }

//        // 获取父栏目ID
//        String parentId = categoryExt.getParentId();
//        if (parentId == null || parentId.isEmpty()) {
//            categoryExt.setParentId(null);
//        } else {
//            mapper.selectList(categoryList);
//            categoryExt.setParentId(parent.getId());
//        }
        categoryList.add(categoryExt);
    }
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

        }

    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {

    }
}
